#include "Enemy.h"
//#include "Global.h"
#include "Resource.h"

Enemy::Enemy(float x, float y)
{
	check_turn = false;

	//_sprite = new Sprite(ResourceMng::GetInst()->GetTexture(L"..\\Resources\\Images\\mario.png"), 150, 0);
	_x = x;
	_y = y;
	_vx = (float)ENEMY_VX;
	_vy = 0;
}

Enemy::Enemy(LPDIRECT3DDEVICE9 d3ddv,  LPDIRECT3DSURFACE9 BackBuffer, LPD3DXSPRITE SpriteHandler, float x, float y)
{
	check_turn = false;

	//_sprite = new Sprite(ResourceMng::GetInst()->GetTexture(L"..\\Resources\\Images\\mario.png"), 150, 0);
	_x = x;
	_y = y;
	_vx = (float)ENEMY_VX;
	_vy = 0;
	_sprite = new Sprite(SpriteHandler, ResourceMng::GetInst(d3ddv, BackBuffer)->GetTexture(L"..\\Resources\\Images\\PlayNho.png"), 150, 0);
}

Enemy::~Enemy()
{
	/*if (_sprite != NULL)
	delete _sprite;*/
}


//void Enemy::Init(LPDIRECT3DDEVICE9 d3ddv,  LPDIRECT3DSURFACE9 BackBuffer, LPD3DXSPRITE SpriteHandler)
//{
//	_sprite = new Sprite(SpriteHandler, ResourceMng::GetInst(d3ddv, BackBuffer)->GetTexture(L"..\\Resources\\Images\\PlayNho.png"), 150, 0);
//}

//void Enemy::Update(int _ScreenWidth, int _ScreenHeight, float gameTime)
//{
//	_x += _vx * gameTime;
//	_y += _vy * gameTime;
//
//	ResetRect();
//
//	if(_vx > 0)
//	{
//		TurnRight();
//	}
//	else
//	{
//		TurnLeft();
//	}
//
//	if(_x >= _ScreenWidth)
//	{
//		TurnLeft();
//	}
//	else if(_x <= 0)
//	{
//		TurnRight();
//	}
//
//	if(_vx != 0)
//		//turtle_cur->Update(time);
//		_sprite->Update(gameTime);
//}

void Enemy::Render()
{
	//Object::Draw(spriteHandler);
	/*float x = this->m_pos.x;
	float y = m_pos.y;*/
	_sprite->Render((int)_x,(int)_y);
}

OBJECT_TYPE Enemy::GetTypeObject()
{
	return OBJECT_ENEMY;
}

/**--------------------------------------------------------
*Description : Turn left Turtle
*Method name : TurnLeft
*Parameters :   
*Return value : void
--------------------------------------------------------**/
void Enemy :: TurnLeft()
{
	check_turn = true;
	//turtle_cur = turtle_left;
	_sprite->SetFrame(9, 11);
	_vx = (float)-ENEMY_VX;
}


/**--------------------------------------------------------
*Description : Turn right Turtle
*Method name : TurnRight
*Parameters :   
*Return value : void
--------------------------------------------------------**/
void Enemy :: TurnRight()
{
	check_turn = false;
	//turtle_cur = turtle_right;
	_sprite->SetFrame(0, 2);
	_vx = (float)ENEMY_VX;
}

void Enemy::Update(list<Object*>* staObjs, list<Object*>* dynObjs, DxInput* input, float gameTime)
{
	_x += _vx * gameTime;
	_y += _vy * gameTime;

	ResetRect();

	if(_vx > 0)
	{
		TurnRight();
	}
	else
	{
		TurnLeft();
	}

	if(_x >= 800)//_ScreenWidth)
	{
		TurnLeft();
	}
	else if(_x <= 0)
	{
		TurnRight();
	}

	if(_vx != 0)
		//turtle_cur->Update(time);
		_sprite->Update(gameTime);
}